The Field of the Invention
The present invention relates generally to object-oriented programming environments, and more particularly, to improved techniques for accessing Java class files.
Recently, the Java programming environment has become quite popular. The Java programming language is a language that is designed to be portable enough to be executed on a wide range of computers ranging from small devices (e.g., pagers, cell phones and smart cards) up to supercomputers. Computer programs written in the Java programming language (and other languages) may be compiled into Java Bytecode instructions that are suitable for execution by a Java virtual machine implementation.
The Java virtual machine is commonly implemented in software by means of an interpreter for the Java virtual machine instruction set but, in general, may be software, hardware, or both. A particular Java virtual machine implementation and corresponding support libraries together constitute a Java runtime environment.
Computer programs in the Java programming language are arranged in one or more classes or interfaces (referred to herein jointly as classes or class files). Such programs are generally platform, i.e., hardware and operating system, independent. As such, these computer programs may be executed without modification on any computer that is able to run an implementation of the Java(trademark) runtime environment.
Object-oriented classes written in the Java programming language are compiled to a particular binary format called the xe2x80x9cclass file format.xe2x80x9d The class file includes various components associated with a single class. These components typically include methods, interfaces, fields, and constant pool associated with the class. In addition, the class file format can include a significant amount of ancillary information that is associated with the class. The class file format is shown in FIG. 1A. The class file format (as well as the general operation of the Java virtual machine) is described in some detail in The Java(trademark) Virtual Machine Specification. Second Edition, by Tim Lindholm and Frank Yellin, which is hereby incorporated herein by reference.
FIG. 1B illustrates a simplified class file 100. As shown in FIG. 1B, the class file 100 includes a constant pool 102 portion, interfaces portion 104, fields portion 106, methods portion 108, and attributes portion 110. The attributes (or attributes table) 110 portion represents the attributes associated with the class file 100. This allows for one or more attributes to be defined, each of which can be associated with one or more components of the class file. As is known to those skilled in the art, the Java virtual machine implementations are allowed to define and use various attributes. In addition, the virtual machine""s implementations ignore attributes that they do not recognize. Thus, a class file may contain one or more attributes, all or none of which may be recognized and/or of interest to a particular virtual machine implementation.
It should be noted that the constant pool 102, interfaces 104, fields 106, methods 108, and attributes 110 can have variable lengths. Thus, typically, the virtual machine needs to sequentially read the class file to find, for example, a particular attribute. However, the particular attribute may not even be contained in the class file, and even if the class file contains this attribute, the process of finding the attribute and then finding various components associated with the attribute can be very costly and/or time consuming. This is partially due to the fact that each of the various portions of the class file may contain hundreds of components with various lengths. Thus, conventionally accessing components of class files can be grossly inefficient. This inefficiency can adversely effect performance of virtual machines, especially those operating with relatively limited memory and/or processing power (e.g., embedded systems).
In view of the foregoing, improved techniques for accessing class files are needed.
Broadly speaking, the present invention relates to improved techniques for accessing Java class files. One aspect of the present invention seeks to provide a mechanism that will generally improve the efficiency of virtual machines by providing a directory for Java class files. The directory can be implemented as an attribute in the attribute portion of the Java class files. As will be appreciated, various components of the Java class file can be accessed efficiently by using the directory. In addition, techniques for accessing various components of Java class files using directories are disclosed. The techniques utilize the directory to allow efficient access to the class file. Thus, unlike conventional techniques, there is no need to perform sequential reads in order to locate various components of the Java class file. This allows for better use of resources. As a result, the invention can improve the performance of virtual machines, especially those that operate with limited resources (e.g., embedded systems).
The invention can be implemented in numerous ways, including as a method, an apparatus, a computer readable medium, and a database system. Several embodiments of the invention are discussed below.
As a method for accessing components of a Java class file, one embodiment of the invention includes the acts of: accessing a directory of the Java class file, wherein the directory lists at least one component of the Java class file; and determining whether one or more components of the Java class file are listed in the directory.
As a method for determining whether a Java class file has an attribute, one embodiment of the invention includes the acts of: determining whether a Java class file has a directory; reading the directory when it is determined that the Java class file has a directory; determining whether at least one attribute is listed in the directory.
As a Java class file suitable for loading into a virtual machine, one embodiment of the invention includes a directory that lists one or more components of the class. The directory includes information relating to the one or more listed components.
As a computer readable media including computer program code for a Java class file suitable for loading into a virtual machine, one embodiment of the invention includes the Java class file directory that lists one or more components of the class file. In addition, the directory provides information relating to one or more components of the class file.
These and other aspects and advantages of the present invention will become more apparent when the detailed description below is read in conjunction with the accompanying drawings.